import { defineStore } from 'pinia'
import { ref } from 'vue'
import { currentUser } from '@/router/api.ts'

interface UserInfo {
  id?: number,
  realName?: string,
  userRole?: string,
  [propName: string]: unknown;
}
export const useLoginUserStore = defineStore('loginUser', () => {
  const loginUser = ref<UserInfo>({
  })

  async function fetchLoginUser() {
    loginUser.value = await currentUser();
  }

  function setLoginUser(newLoginUser: UserInfo): void {
      loginUser.value = newLoginUser
  }

  return {loginUser, fetchLoginUser, setLoginUser};
})
